//
//  JMMyBindingTVController.m
//  jiMuOperate
//
//  Created by 胡梅方 on 16/5/9.
//  Copyright © 2016年 jinXinFengLi. All rights reserved.
//

#import "JMMyBindingTVController.h"
#import "JMMyBindingCell.h"
#import "JMMyBindingReturn.h"
#import "MJRefresh.h"
 NSString *const bindingCell = @"MyBindingCell";
@interface JMMyBindingTVController ()
{
    int _pagNum;
    NSString * _token;
}
@property(nonatomic,strong)NSMutableArray *myBindingArr;
@end

@implementation JMMyBindingTVController

-(NSMutableArray*)myBindingArr
{
    if (_myBindingArr==nil) {
        _myBindingArr = [NSMutableArray array];
    }
    return _myBindingArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _token = [UserEntity shardUserInfo].access_token;
    [self requestGetMyBindStrategyPeopleListWithToken:_token page:1 pageSize:10 IsHeaderR:NO];
    HIDETABVLINE(self.tableView);
//    [self.tableView registerClass:[JMMyBindingCell class] forCellReuseIdentifier:bindingCell];
}
-(void)requestGetMyBindStrategyPeopleListWithToken:(NSString*)token page:(NSInteger)page pageSize:(NSInteger)pagesize IsHeaderR:(BOOL)isHeaderR
{
    NSString *url = [NSString stringWithFormat:@"%@%@&page=%ld&pageSize=%ld",JMURLGetMyBindStrategyPeopleList,token,(long)page,(long)pagesize];
    NSArray *arrayR = @[@"",url,@"GET"];
    [Request startRequestWithArray:arrayR FinishedBlock:^(NSData *data) {
        NSDictionary *dict = [JMData dictAndTestData:data];
        NSLog(@"dictdgfg%@",dict);
        JMMyBindingReturn *myBinding = [JMMyBindingReturn objectWithKeyValues:dict];
        
        if ([myBinding.State intValue]>= 0) {
            self.myBindingArr = [JMMyBindingInfo objectArrayWithKeyValuesArray:myBinding.data];
            
            
            NSMutableArray *aryM = [NSMutableArray array];
            for (JMMyBindingInfo *myBindingInfo00 in aryM) {
                if (![self.myBindingArr containsObject:myBindingInfo00]) {
                    [aryM addObject:myBindingInfo00];
                }
            }
            [self.myBindingArr addObjectsFromArray:aryM];
            if (isHeaderR) {
                [self.tableView headerEndRefreshing];
            }else{
                [self.tableView footerEndRefreshing];
            }
            
            
            [self.tableView reloadData];
        }
        
    } FailBlock:^(NSString *string) {
        SHOWALERT(@"服务器繁忙，请梢后重试");
    }];
}


#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.myBindingArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    JMMyBindingCell *cell =(JMMyBindingCell*) [tableView cellForRowAtIndexPath:indexPath];
    
    if (cell == nil) {
        cell = [[JMMyBindingCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:bindingCell];
        JMMyBindingInfo *myBindInfo = self.myBindingArr[indexPath.row];
        [JMData requestOrSetImgWithImageView:cell.personImage ProductImageUrl:myBindInfo.HeadImg];
        if (myBindInfo.NickName == NULL) {
            myBindInfo.NickName = @"钱要多多";
        }
        cell.nameLabel.text = myBindInfo.NickName;
        
        cell.levelLab.text = [NSString stringWithFormat:@"级别:%@",myBindInfo.Level];
        cell.levelLab.textColor = [UIColor blackColor];
        cell.bindingLab.text = [NSString stringWithFormat:@"绑定:%@",myBindInfo.BindNumber];
        cell.winProbaNum.text =  [NSString stringWithFormat:@"%@%%",myBindInfo.PutWinRate];
        
        
        
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70*SCREEN_HEIGHT/568;
}

@end
